package com.briup.bms.common.utils;

import java.util.ArrayList;
import java.util.List;

import lombok.Getter;

/**
 * 分页数据展示工具类。
 * @author guomiao
 *	根据页面要显示的分页信息数据，抽取出来的额，每页数据需要具有的共有特征和行为。
 */
@Getter
public class Page<T> {
	private int currentPage; //当前页码
	private int pageSize;//每页数据大小
	private int total; // 数据的总个数。
	private int nextPage; //下一页页码
	private int prePage; //上一页页码
	private boolean hasPrePage; //是否有上一页
	private boolean hasNextPage; //是否有下一页
	private boolean isFirst; //是否是第一页
	private boolean isLast; //是否是最后一页。
	private int totalPage; //总页码。
	private List<T> datas = new ArrayList<>(); //当前页中要显示的所有数据
	public Page(int currentPage,int pageSize) {
		this.currentPage = currentPage;
		this.pageSize = pageSize;
	}
	public void setTotal(int total) {
		this.total = total;
		this.totalPage = total/pageSize;
		this.totalPage = total%pageSize==0?this.totalPage:this.totalPage+1;
		this.isFirst = currentPage==1;
		this.isLast = currentPage==totalPage;
		this.hasNextPage = currentPage<totalPage;
		this.nextPage = this.hasNextPage?currentPage+1:totalPage;
		this.hasPrePage = currentPage>1;
		this.prePage = this.hasPrePage?currentPage-1:1;
	}
	public void setDatas(List<T> datas) {
		this.datas = datas;
	}
}
